package com.zg.common.core.converter;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.sql.Time;

/**
 * 将字符串转java.sql.Time
 * @author Zxb
 */
@Component
public class TimeConverter implements Converter<String, Time> {

    @Override
    public Time convert(@Nonnull String source) {
        if(StrUtil.isBlank(source)){
            return null;
        }
        return new Time(DateUtil.parse(source,"HH:mm:ss").getTime());
    }

}
